package com.ning.city.controller;

import com.ning.city.bean.Info;
import com.ning.city.bean.InfoType;
import com.ning.city.dto.InfoDto;
import com.ning.city.service.InfoService;
import com.ning.city.vo.CommonResult;
import com.ning.city.vo.PageData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Ning 242741154@qq.com
 * @date 2021/1/7 14:27
 */
@RestController
@RequestMapping("/info")
public class InfoController {
    private final InfoService infoService;

    public InfoController(InfoService infoService) {
        this.infoService = infoService;
    }

    @RequestMapping(path = "/types")
    public CommonResult<List<InfoType>> types() {
        List<InfoType> data = infoService.getAllTypes();
        return new CommonResult<>(data);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/page")
    public CommonResult<PageData<Info>> page(@RequestBody @Validated InfoDto.PageInfo dto) {
        return new CommonResult<>(infoService.getPageData(dto));
    }

    @RequestMapping(method = RequestMethod.POST, path = "/add")

    public CommonResult<Boolean> add(@RequestBody @Validated InfoDto.Add dto) {
        return new CommonResult<>(infoService.add(dto));
    }

    @RequestMapping(method = RequestMethod.GET, path = "/pay")
    public CommonResult<Boolean> pay(String infoId) {
        return new CommonResult<>(infoService.pay4(infoId));
    }

    @RequestMapping(method = RequestMethod.GET, path = "/recommendInfos")
    public CommonResult<List<Info>> recommendInfos() {
        return new CommonResult<>(infoService.getRecommendInfos());
    }
}
